package com.zhiyou100.dao;

import com.zhiyou100.entity.Student;
import com.zhiyou100.util.mybatis.MyBatis;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * @author yang
 * @className StudentDao
 * @packageName com.zhiyou100.dao
 * @Description TODO 学生 dao
 * @date 2020-08-12 20:51
 */
public class StudentDao implements AutoCloseable {

    private static final Logger log = Logger.getLogger(StudentDao.class);

    SqlSession sqlSession = MyBatis.get(); 

    public List<Student> getAll() {

        return sqlSession.selectList("getAll");

    }

    public Student getOneBySid(int sid) {

        return sqlSession.selectOne("getBuSid", sid);

    }

    public void addOne(Student from) {

        sqlSession.insert("addOne", from);

    }

    public void delOneBySid(int sid) {
        sqlSession.delete("deleteOneBySid", sid);
    }

    public void updateOne(Student from) {
        sqlSession.update("updateOne", from);
    }


    @Override
    public void close() throws Exception {
        log.info("StudentDao" + "老子关闭了");
        if (sqlSession != null) {
            sqlSession.close();
        }
    }
}
